﻿--获得单位异动人员
CREATE PROCEDURE [dbo].[proc_Employee_GradeMove_GetList]
(
	@CompanyId int,
	@EName nvarchar(50),
	@StartIndex int,
	@EndIndex int

)
as

	Begin
		
		;WITH list As(Select ROW_NUMBER() OVER (Order By EC.Id DESC)AS Row,
			EC.Id,
			(select ENumber from Employee E where EC.EId=E.Id) as ENumber,
			(select ETempNumber from Employee E where EC.EId=E.Id) as ETempNumber,
			EC.EId,
			(select EName from Employee E where EC.EId=E.Id) as EName,
			(select Sex from Employee E where EC.EId=E.Id) as Sex,
			(select CompanyName from Company where id=(select companyid from employee E where EC.EId=E.Id)) as CompanyName,
			(select DName from Department where id=(select departmentid from employee E where EC.EId=E.Id)) as DName,
			(select PostName from Post P where id=(select PostId from employee E where EC.EId=E.Id)) as PostName,
			(select Title from Grade G where id=(select GradeId from employee E where EC.EId=E.Id)) as GradeName,
			EC.Audit,
			EC.AuditPerson,
			EC.AuditTime
			From Employee_CompanyMove EC 
		Where (@CompanyId=0 Or (select companyid from employee E where EC.EId=E.Id)=@CompanyId) And (@EName is null Or (select EName from Employee E where EC.EId=E.Id) like '%'+ @EName +'%') 
		)
		Select * From list Where Row between @StartIndex and @EndIndex
	
	End
	RETURN
